import { createRouter, createWebHistory } from 'vue-router'
import Login from '@/views/Login/index.vue'
import Home from '@/views/Home/index.vue'
import HomeMain from '@/views/Home/component/home.vue'
import User from '@/views/User/index.vue'
import Merchant from '@/views/Merchant/index.vue'
import Product from '@/views/Product/index.vue'
import Order from '@/views/Order/index.vue'
import OrderList from '@/views/Order/component/orderlist.vue'
import MakeOrder from '@/views/Order/component/makeorder.vue'
import Statistics from '@/views/Statistics/index.vue'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  // path和component对应关系的位置
  routes: [
    {
      path: '/',
      name: 'login',
      component: Login
    },
    {
      //默认渲染页，当我们访问/时，Home也会被渲染
      path: '/home',
      name: 'home',
      component: Home,
      redirect: '/home/dashboard',
      children: [
        {
          path: 'dashboard',
          name: 'home-dashboard',
          component: HomeMain
        },
        {
          path: 'user',
          name: 'user',
          component: User,
          redirect: '/home/user/list',
          children: [
            {
              path: 'list',
              name: 'user-list',
              component: () => import('@/views/User/component/user.vue')
            }
          ]
        },
        {
          path: 'merchant',
          name: 'merchant',
          component: Merchant,
          redirect: '/home/merchant/list',
          children: [
            {
              path: 'list',
              name: 'merchant-list',
              component: () => import('@/views/Merchant/component/merchant.vue')
            }
          ]
        },
        {
          path: 'product',
          name: 'product',
          component: Product,
          redirect: '/home/product/list',
          children: [
            {
              path: 'list',
              name: 'product-list',
              component: () => import('@/views/Merchant/component/commodity.vue')
            },
            {
              path: 'category',
              name: 'product-category',
              component: () => import('@/views/Merchant/component/category.vue')
            }
          ]
        },
        {
          path: 'order',
          name: 'order',
          component: Order,
          redirect: '/home/order/list',
          children: [
            {
              path: 'list',
              name: 'order-list',
              component: OrderList
            },
            {
              path: 'make',
              name: 'order-make',
              component: MakeOrder
            }
          ]
        },
        {
          path: 'statistics',
          name: 'statistics',
          component: Statistics
        },
        {
          path: 'permission',
          name: 'permission',
          component: () => import('@/views/Permission/index.vue'),
          redirect: '/home/permission/permission',
          children: [
            {
              path: 'permission',
              name: 'permission-management',
              component: () => import('@/views/Permission/component/permission.vue')
            },
            {
              path: 'role',
              name: 'role-management',
              component: () => import('@/views/Permission/component/role.vue')
            },
            {
              path: 'user',
              name: 'user-management',
              component: () => import('@/views/Permission/component/user.vue')
            }
          ]
        }
      ]
    }
  ]
})


export default router